extends layout.pug

block content

  div.row
    div.col-sm-6.col-sm-offset-3
      div
        div.form-group
          div.input-group
            div.input-group-addon
              i.fa.fa-user
            input.form-control#user(type="text" placeholder="用户名")
        div.form-group
          div.input-group
            div.input-group-addon
              i.fa.fa-lock
            input.form-control#pwd(type="password" placeholder="密码")
        div.form-group.clearfix
          button.btn.btn-primary.pull-right#login= "登录"

  script.
      $('#login').click(function () {
          var user = $('#user').val().trim(),
              pwd = $('#pwd').val().trim();
          if (!user || !pwd) {
              $.moyuAlert("请输入用户名或秘密");
          } else {
              $.post("/api/login", {user: user, pwd: pwd}, function (data) {
                  if (data.code == 200) {
                      window.location.href = "/";
                  } else {
                      $.moyuAlert("用户名或秘密错误");
                  }
              }, 'json');
          }
      });
